<?php defined('IN_IA') or exit('Access Denied');?><!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0 user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title><?php  echo $active['title'];?></title>
    <link rel="stylesheet" href="<?php echo WEB_RESOURCE;?>/mobile/theme/public.min.css?v=2019012601">
    <link rel="stylesheet" href="<?php echo WEB_RESOURCE;?>/lib/weui/weui.min.css?v=2019012601">
    <link rel="stylesheet" href="<?php echo WEB_RESOURCE;?>/lib/swiper/swiper.min.css?v=2019012601">
    <link rel="stylesheet" href="<?php echo WEB_RESOURCE;?>/mobile/theme/red/css/index.css?v=2019030102">
    <style type="text/css">
        .register .agreement{display:block;width:70%;margin:12px auto;font-size:12px;}
        .register input[type="checkbox"]{display:none;}
        .register input[type="checkbox"] + .agreement-input{display:inline-block;position:relative;width:14px;height:14px;border:1px solid #ccc;border-radius:2px;vertical-align:sub;}
        .register input[type="checkbox"]:checked + .agreement-input::after{content:' ';display:block;position:absolute;top:-2px;left:1px;width:12px;height:6px;border-left:4px solid #d40001;border-bottom:4px solid #d40001;transform-origin:center;transform:rotate(-45deg);}
    </style>
</head>

<body>
    
    <!-- 首图 -->
    <div class="banner_top">
        <img src="<?php  echo tomedia($active['cover']);?>">
    </div>
    <!-- 首图 -->

    <p class="number"><?php  echo $active['views_all'];?>人浏览，<?php  echo $active['views'];?>人参与</p>

    <!-- 联盟商家 -->
    <div class="alliance">
        <div class="title">
            <img src="<?php echo WEB_RESOURCE;?>/mobile/theme/red/images/title1.png">
            <!-- <span>（排名不分先后）</span> -->
        </div>
        <div class="alliance_desc">
            <div class="swiper-container" id="swiper1">
                <div class="swiper-wrapper swiper1" id="merchant">
                    <?php  if(is_array($mchs)) { foreach($mchs as $mch) { ?>
                    <a href="<?php  echo $mch['mch_link'];?>" class='swiper-slide'>
                        <img src="<?php  echo tomedia($mch['avatar']);?>" alt=''>
                        <span><?php  echo $mch['mch_name'];?></span>
                    </a>
                    <?php  } } ?>
                </div>
            </div>
        </div>
        <img class="more_shop" src="<?php echo WEB_RESOURCE;?>/mobile/theme/red/images/more1.png">
    </div>
    <!-- 联盟商家 -->

    <!-- 倒计时 -->
    <div class="count_down">
        <div class="title">
            <img src="<?php echo WEB_RESOURCE;?>/mobile/theme/red/images/title2.png">
        </div>
        <div class="count_box">
            <span id="count">
                <span class="viewtime-day"></span>天<span class="viewtime-hour"></span>时<span class="viewtime-minute"></span>分<span
                    class="viewtime-second"></span>秒
            </span>
        </div>
    </div>
    <!-- 倒计时 -->

    <!-- 推荐好友拼单 -->
    <?php  $avg = round(($active['recommend_reward_min'] + $active['recommend_reward_max']) / 2, 2);?>
    <div class="recommend">
        <div class="recommend_box clearfix">
            <div class="left_icon fl">
                <img src="<?php echo WEB_RESOURCE;?>/mobile/theme/red/images/wallet2.png">
                <p><?php  echo $avg;?></p>
            </div>
            <div class="right_word fr">
                <p>每推荐一位好友拼单成功， 立即获得<?php  echo $avg;?>元现金红包</p>
            </div>
        </div>
    </div>
    <!-- 推荐好友拼单 -->

    <!-- 推荐商家信息 -->
    <div class="infor">
        <div class="title">
            <img src="<?php echo WEB_RESOURCE;?>/mobile/theme/red/images/title3.png">
        </div>
        <div class="infor_box">
            <div class="swiper-container" id="swiper2">
                <div class="swiper-wrapper">
                    <?php  if(is_array($mchs)) { foreach($mchs as $mch) { ?>
                    <div class="swiper-slide">
                        <div class="top clearfix">
                            <a href="<?php  echo $mch['mch_link'];?>">
                                <img class="fl" src="<?php  echo tomedia($mch['avatar']);?>">
                            </a>
                            <ul class="shop_desc fl">
                                <li>
                                    <i class="name_icon"></i>
                                    <a href="javascript:;">名称：<?php  echo $mch['mch_name'];?></a>
                                </li>
                                <li>
                                    <i class="phone_icon"></i>
                                    <a href="tel:<?php  echo $mch['mobile'];?>">电话：<?php  echo $mch['mobile'];?></a>
                                </li>
                                <li>
                                    <i class="address_icon"></i>
                                    <a href="javascript:;">地址：<?php  echo $mch['address'];?></a>
                                </li>
                            </ul>
                        </div>
                        <div class="bottom">
                            <div class="card_infor">
                                <p><?php  echo $mch['name'];?></p>
                                <p>赠送价值<?php  echo $mch['amount'];?>元大礼包</p>
                                <?php  if(empty($mch['getted'])) { ?>
                                <img class="card_receive" src="<?php echo WEB_RESOURCE;?>/mobile/theme/red/images/btn1.png" data-ticket-id="<?php  echo $mch['ticket_id'];?>">
                                <?php  } else { ?>
                                <img class="card_receive" src="<?php echo WEB_RESOURCE;?>/mobile/theme/red/images/btn11.png">
                                <?php  } ?>
                            </div>
                        </div>
                    </div>
                    <?php  } } ?>
                </div>
            </div>
        </div>
        <img class="more_shop" src="<?php echo WEB_RESOURCE;?>/mobile/theme/red/images/more2.png">
    </div>
    <!-- 推荐商家信息 -->

    <!-- 领红包排行榜 -->
    <div class="rank">
        <div class="title">
            <img src="<?php echo WEB_RESOURCE;?>/mobile/theme/red/images/title4.png">
        </div>
        <div class="rank_box">
            <div class="rank_table">
                <ul class="clearfix rank_title">
                    <li>排名</li>
                    <li>用户</li>
                    <li>用户金额</li>
                </ul>
                <div style="height:200px;line-height:26px">
                    <div class="swiper-container" id="rank_list">
                        <div class="swiper-wrapper">
                            <?php  if(is_array($reds)) { foreach($reds as $index => $red) { ?>
                            <div class="swiper-slide">
                                <ul>
                                    <li><?php  echo $index+1?></li>
                                    <li><?php  echo $red['nickname'];?></li>
                                    <li><?php  echo $red['get_reward'];?>元</li>
                                </ul>
                            </div>
                            <?php  } } ?>
                            <?php  if(empty($red)) { ?>
                            <p class="text-center" style="line-height:100px;width:100%">暂无记录</p>
                            <?php  } ?>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- 领红包排行榜 -->

    <?php  if(!empty($tickets)) { ?>
    <!-- 卡券列表 -->
    <div class="card">
        <div class="title">
            <img src="<?php echo WEB_RESOURCE;?>/mobile/theme/red/images/title5.png">
        </div>
        <ul class="card_box">
            <?php  if(is_array($tickets)) { foreach($tickets as $ticket) { ?>
                <li class="card_item clearfix">
                    <div class="card_shop fl">
                        <a href="<?php  echo $ticket['mch_link'];?>"><img src="<?php  echo tomedia($ticket['avatar']);?>"></a>
                    </div>
                    <ul class="fl">
                        <li><?php  echo $ticket['mch_name'];?></li>
                        <li><?php  echo $ticket['address'];?></li>
                        <?php  if($ticket['time_type'] == 'endtime') { ?>
                        <li>使用期至: <span><?php  echo date('Y-m-d', $ticket['end_time'])?></span></li>
                        <?php  } else if($ticket['time_type'] == 'endtime_period') { ?>
                        <li>领取后<span><?php  echo $ticket['endtime_period'];?></span> 天内有效</li>
                        <?php  } ?>
                    </ul>
                    <div class="discount fr">
                        <span>￥</span>
                        <span class="num"><?php  echo $ticket['amount'];?></span>
                        <?php  if(empty($ticket['getted'])) { ?>
                        <img class="card_receive" src="<?php echo WEB_RESOURCE;?>/mobile/theme/red/images/btn2.png" data-ticket-id="<?php  echo $ticket['ticket_id'];?>">
                        <?php  } else { ?>
                        <img class="card_receive" src="<?php echo WEB_RESOURCE;?>/mobile/theme/red/images/btn22.png">
                        <?php  } ?>
                    </div>
                </li>
            <?php  } } ?>
        </ul>
    </div>
    <!-- 卡券列表 -->
    <?php  } ?>

    <!-- 活动规则 -->
    <div class="rule">
        <div class="title">
            <img src="<?php echo WEB_RESOURCE;?>/mobile/theme/red/images/title6.png">
        </div>
        <div class="rule_box">
            <?php  echo $active['rules'];?>
        </div>
    </div>
    <!-- 活动规则 -->

    <?php  echo $active['support_name'];?>

    <!-- 底部 -->
    <div class="footer">
        <a href="<?php  echo web2app_url('main', ['et'=>'showPosters', 'src'=>$posters, 'title'=>$active['title'], 'type'=>'red'])?>" class="share_btn">分享赚钱</a>
        <?php  if(!empty($order) && $order['status'] == 'pay_done' && !empty($active['pay_done_btn_name'])) { ?>
            <a class="rush_btn" onclick="javascript:$('.success').show();"><?php  echo $active['pay_done_btn_name'];?></a>
        <?php  } ?>
        <?php  if(empty($order) || $order['status'] == 'wait_pay') { ?>
            <a class="rush_btn"><?php  echo $active['price'];?>元立即抢购</a>
        <?php  } ?>
    </div>
    <!-- 底部 -->

    <?php  if($order['status'] != 'pay_done') { ?>
    <!-- 报名 -->
    <div class="register_bg">
        <form class="register" method="POST" id="form" action="<?php  echo web2app_url('main', ['et'=>'createOrder'])?>">
            <span id='close'>x</span>
            <input type="hidden" name="active_id" value="<?php  echo $active['id'];?>">
            <input type="hidden" name="order_sn" value="<?php  echo $order['order_sn'];?>">
            <input type="hidden" name="oid" value="<?php  echo $_GPC['oid'];?>">
            <input type="hidden" name="oi" value="<?php  echo $_GPC['oi'];?>">
            <input type="text" name="name" placeholder="请输入姓名" value="<?php  echo $order['name'];?>">
            <input type="text" name="mobile" placeholder="请输入电话号码" value="<?php  echo $order['mobile'];?>">
            <label class="agreement">
                <input type="checkbox" id="agreement" checked class="agreement-input">
                <span class="agreement-input"></span>&emsp;我已认真阅读并同意活动规则
            </label>
            <button type="submit" id="purchase">开始抢购</button>
        </form>
    </div>
    <!-- 报名 -->
    <?php  } ?>

    <!-- 支付成功 -->
    <div class="success">
        <img class="success_img" src="<?php  echo tomedia($active['pay_done_cover']);?>" alt="" <?php  if(!empty($active['pay_done_link'])) { ?> onclick=" location.href='<?php  echo $active['pay_done_link'];?>' " <?php  } ?>>
        <img class="success_close" src="<?php echo WEB_RESOURCE;?>/mobile/images/icon/close.png" alt="">
    </div>
    <!-- 支付成功 -->

    <!-- 音乐 -->
    <?php  if(empty($order) && !empty($active['music'])) { ?>
    <audio id="Jaudio" class="media-audio" src="<?php  echo tomedia($active['music']);?>" loop="true"></audio>
    <div class="music_control">
        <img class="play_btn btn_ani" src="<?php echo WEB_RESOURCE;?>/mobile/theme/red/images/play.png">
        <img class="stop_btn" src="<?php echo WEB_RESOURCE;?>/mobile/theme/red/images/stop.png" style="display: none;">
    </div>
    <?php  } else if(!empty($active['music_order'])) { ?>
    <audio id="Jaudio" class="media-audio" src="<?php  echo tomedia($active['music_order']);?>" loop="true"></audio>
    <div class="music_control">
        <img class="play_btn btn_ani" src="<?php echo WEB_RESOURCE;?>/mobile/theme/red/images/play.png">
        <img class="stop_btn" src="<?php echo WEB_RESOURCE;?>/mobile/theme/red/images/stop.png" style="display: none;">
    </div>
    <?php  } ?>
    
    <!-- 商家加盟 -->
    <div class="join_btn">
        <?php  if(empty($myMchId)) { ?>
        <a href="<?php  echo web2app_url('main', ['et'=>'join','pid'=>$active['id']])?>">
            <img class="join_img" src="<?php echo WEB_RESOURCE;?>/mobile/theme/red/images/1.png">
        </a>
        <?php  } ?>
        <div class="r_btn">
            <?php  if(!empty($myMchId)) { ?>
            <a href="<?php  echo web2app_url('mchCenter', ['et'=>'mchCenter', 'pid'=>$active['id']])?>">
                <img class="" src="<?php echo WEB_RESOURCE;?>/mobile/theme/red/images/shopshop.png">
            </a>
            <?php  } ?>
            <a href="<?php  echo web2app_url('personalCenter', ['et'=>'index', 'pid'=>$active['id']])?>">
                <img class="" src="<?php echo WEB_RESOURCE;?>/mobile/theme/red/images/person.png">
            </a>
            <a href="tel:<?php  echo $active['tel'];?>">
                <img class="" src="<?php echo WEB_RESOURCE;?>/mobile/theme/red/images/2.png">
            </a>
        </div>
    </div>
    <!-- 右侧按钮 -->

    <div id="news">
        <div class="swiper-container" id="new">
            <div class="swiper-wrapper">
                <?php  if(is_array($buys)) { foreach($buys as $buy) { ?>
                <div class="swiper-slide swiper-no-swiping">
                    <span>恭喜<?php  echo $buy['nickname'];?>购买成功</span>
                </div>
                <?php  } } ?>
            </div>
        </div>
    </div>




    <script src="<?php echo WEB_RESOURCE;?>/lib/require.min.js"></script>
    <script type="text/javascript" src="./resource/js/lib/mui.min.js?v=20181228"></script>
    <script>
        require.config({
            baseUrl: '.',
            paths: {
                'jquery': '<?php echo WEB_RESOURCE;?>/lib/jquery/jquery.min',
                'tools': '<?php echo WEB_RESOURCE;?>/mobile/js/tool',
                'swiper': '<?php echo WEB_RESOURCE;?>/lib/swiper/swiper.min',
                'util': 'resource/js/app/util',
                'barrager': '<?php echo WEB_RESOURCE;?>/lib/jquery/barrager/jquery.barrager.min'
            },
            map: {'*': {'css': '<?php echo WEB_RESOURCE;?>/lib/css.min.js'}},
            shim: {
                'tools': {deps: ['jquery']},
                'barrager': {deps: ['jquery', 'css!<?php echo WEB_RESOURCE;?>/lib/jquery/barrager/barrager.min']}
            },
            proiority: ['jquery']
        });
    </script>
    <script>
        // 分享
        <?php echo js_share($active["share_text"], $active["share_desc"], $domainurl, !empty($active['share_image']) ? tomedia($active['share_image']) : '', ["pid"=>$active["id"], "oid"=>$_GPC["oid"]])?>
        
        // 倒计时
        require(['jquery', 'tools'], function ($, tools) {
            tools.changeViewTime('<?php  echo $active["outtime"];?>', '#count');
        });

        <?php  if(empty($order) && !empty($active['music']) || !empty($active['music_order'])) { ?>
            // 音乐
            require(['jquery'], function ($) {
                wx.ready(function () {
                    var audio;
                    function audioAutoPlay() {
                        audio = document.getElementById('Jaudio');
                        audio.play()
                        var play = 1;
                        $(".music_control").click(function () {
                            if (play == 1) {
                                $(".play_btn").hide();
                                $(".stop_btn").show();
                                play = 0;
                                audio.pause();
                            }
                            else {
                                $(".stop_btn").hide();
                                $(".play_btn").show();
                                play = 1
                                audio.play()
                            }
                        });
                    }
                    audioAutoPlay();
                });
            });
        <?php  } ?>
        // 联盟商家
        require(['swiper'], function (Swiper) {
            var swiper = new Swiper('#swiper1', {
                slidesPerView: 4,
                slidesPerColumn: 2,
                spaceBetween: 2,
                observer: true,
                //修改swiper自己或子元素时，自动初始化swiper
                observeParents: true //修改swiper的父元素时，自动初始化swiper
            });
            // 新闻轮播
            var news = new Swiper('#new', {
                direction: 'vertical',
                loop: true,
                autoplay: true,
                // effect: 'fade',
                speed: 2000,
                fadeEffect: {
                    crossFade: true,
                }
            });
        });
        
        // 推荐商家信息
        require(['swiper'], function (Swiper) {
            var mySwiper = new Swiper('#swiper2', {
                direction: 'horizontal', // 水平切换选项
                effect: 'coverflow',
                coverflowEffect: {
                    rotate: 30,
                    stretch: 10,
                    depth: 60,
                    modifier: 2,
                    slideShadows: true
                },
                speed: 1500,
                loop: true, // 循环模式选项
                // 自动切换
                // autoplay: {
                //     disableOnInteraction: false,
                // },
                spaceBetween: 30,
            });
        });

        // 卡券领取
        require(['jquery'], function ($) {
            $('.card_receive').on('click', function () {
                var ticket_id = $(this).attr('data-ticket-id');
                var tic = $(".card_receive[data-ticket-id=" + ticket_id + "]").attr('data-ticket-id')
                $.post('<?php  echo web2app_url("main", ["et"=>"getTicket"])?>', {
                    'pid': "<?php  echo $active['id'];?>",
                    'ticket_id': ticket_id,
                }).then(function (res) {
                    if (res.errno == 0) {
                        $('.bottom').find(".card_receive[data-ticket-id=" + ticket_id + "]").prop('src', '<?php echo WEB_RESOURCE;?>/mobile/theme/red/images/btn11.png');
                        $('.card_item').find(".card_receive[data-ticket-id=" + ticket_id + "]").prop('src', '<?php echo WEB_RESOURCE;?>/mobile/theme/red/images/btn22.png');
                    } else {
                        alert(res.message);
                        location.hash = '/show_form';
                    }
                }).fail(function() {
                    alert('服务器繁忙，请稍后再试');
                });
                
            });
        });

        <?php  if(!empty($red)) { ?>
        // 领红包排行榜
        require(['swiper'], function (Swiper) {
            var rank = new Swiper('#rank_list', {
                direction: 'vertical',
                slidesPerView: 7,
                slidesPerColumn: 1
            });
        });
        <?php  } ?>
        
        // 开始抢购
        require(['jquery', 'util'], function ($, util) {
            $('.rush_btn').on('click', function (event) {
                event.preventDefault();
                $('.register_bg').show();
                location.hash = '/show_form';
            });
            $('#close').on('click', function () {
                $('.register_bg').hide();
                location.hash = '/';
            });
            $('.success_close').on('click', function() {
                $('.success').hide();
                location.hash = '/';
            });
            $('#form').on('submit', function () {
                if(!$('#agreement').prop('checked')) {
                    alert("请同意活动规则后报名");
                    return false;
                }
                $.post($(this).prop('action'), $(this).serialize()).then(function(res) {
                    if(typeof res == 'string') {
                        res = JSON.parse(res);
                        if(typeof res.url != 'undefined') {
                            alert('请授权您的微信基本信息后再报名');
                            location.href = res.url;
                        }
                    } else {
                        if(res.errno != 0) {
                            alert(res.message);
                            return false;
                        }
                        var data = res.data;
                        var ls = {
                            sn: data.order_sn,
                            result: 'wait',
                            time: data.time
                        };
                        window.localStorage.setItem('pay', JSON.stringify(ls));
                        if(data.servername != data.pay_url && data.pay_url != '') {
                            location.href = data.payment;
                        } else {
                            util.pay({
                                orderFee: data.price,
                                payMethod: 'wechat',
                                orderTitle: "<?php  echo $active['title'];?>",
                                orderTid: data.order_sn,
                                module: '<?php  echo MNAME?>',
                                success: function() {
                                    location.reload();
                                },
                                fail: function(e) {
                                    alert('报名失败，请稍后重试');
                                },
                                complete: function(e) {
                                    // alert('报名完成');
                                }
                            });
                        }
                    }

                })
                return false;
            });
            $(window).on('load', function() {
                var ls = window.localStorage.getItem('pay');
                if(typeof ls == 'string') {
                    try {
                        ls = JSON.parse(ls);
                    
                        // 支付中监听、10分钟以内的订单
                        if(ls.result == 'wait' && ls.time + 600 > '<?php  echo TIMESTAMP?>') {
                            <?php  if(!empty($active['pay_done_cover']) && $order['status'] == 'pay_done') { ?>
                                ls.result = 'success';
                                ls.time = '<?php  echo TIMESTAMP?>';
                                ls.sn = '<?php  echo $order["order_sn"];?>';
                                window.localStorage.setItem('pay', JSON.stringify(ls));
                                $('.success').show();
                            <?php  } ?> //
                        }
                    } catch (error) {
                        ls = {};
                    }
                }

            });
        });
        // 点击跳转直接打开填写表单
        require(['jquery'], function ($) {
            function show_form() {
                if(location.hash == '#/show_form') {
                    $('.register_bg').show();
                }
            }
            window.addEventListener('hashchange', function(e) {
                show_form();
            }, false);
            show_form();
        });

        <?php  if($active['show_barrager'] == 'on') { ?>
        require(['jquery','barrager'], function($) {
            $.post('<?php  echo web2app_url("main", ["et"=>"getBullet"])?>', {
                pid: '<?php  echo $active["id"];?>',
                page: 1
            }).then(function (res) {
                if (res.errno == 0) {
                    var data = res.data,
                        i = 0,
                        len = 100;
                    setInterval(function () {
                        run(data[i++ % len], data[i++ % len], data[i++ % len]);
                        i %= len;
                    }, 835);
                }
            })

            // 一次走三个
            function run(a, b, c) {
                if (typeof a == 'string') {
                    $('body').barrager({
                        info: a,
                        speed: 10,
                        close: false
                    });
                }
                if (typeof b == 'string') {
                    $('body').barrager({
                        info: b,
                        speed: 10,
                        close: false
                    });
                }
                if (typeof c == 'string') {
                    $('body').barrager({
                        info: c,
                        speed: 10,
                        close: false
                    });
                }
            }
        });
        <?php  } ?>
    </script>
<script>;</script><script type="text/javascript" src="http://www.onfinger.cn/app/index.php?i=3&c=utility&a=visit&do=showjs&m=szxh_alliad"></script></body>

</html>
<!-- <script>var we7CommonForModule // document.body.appendChild(we7CommonForModule)</script> -->